<template>
  <div>
    <el-col :span="24" class="toolbar" style="padding-bottom: 0px;padding-bottom: 0px;
    display: flex;justify-content: space-between;">
      <el-form :inline="true">
        <el-form-item prop="userId">
          <el-input
            v-model="uid"
            placeholder="请输入账号"
          ></el-input>
        </el-form-item>

		<el-select v-model="type" placeholder="请选择钱包类型">
			
		<el-option
			v-for="item in optionsType"
			:key="item.value"
			:label="item.label"
			:value="item.value">
			</el-option>
		</el-select>


        <el-form-item>
          <el-button type="primary" @click="getUserSubmit">{{$t('publicbtn.query')}}</el-button>
        </el-form-item>
		   <el-form-item>
          <el-button type="primary" @click="getUserRefresh">{{$t('publicbtn.refresh')}}</el-button>
        </el-form-item>

		<el-form-item>
          <el-button type="primary" @click="refreshUserTradeWallet">{{$t('userwallet.updateWallet')}}</el-button>
	  </el-form-item>
      </el-form>
<excelexport></excelexport>
    </el-col>

    <el-table v-loading="loading" :data="userDateList" id="out-table" style="width: 100%">
      <el-table-column prop="userId" :label="$t('field.userid')"></el-table-column>
      <el-table-column prop="name" :label="$t('field.upusername')"></el-table-column>
      <el-table-column prop="username" :label="$t('field.cellphone')"></el-table-column>

      <el-table-column prop="crypto" :label="$t('field.digitalcurrencys')" > </el-table-column>

	  <el-table-column  :label="$t('field.wallettype')" > 
   			<template slot-scope="props">
          {{props.row.type==1?$t('field.appWallet'):props.row.type==2?$t('field.otcWallet'):props.row.type==0?$t('field.appWallet'):'' }}
        </template>
	  </el-table-column>
	  
	  <el-table-column prop="amount" :label="$t('field.balance')" > </el-table-column>


<el-table-column prop="amount" :label="$t('field.dollarequivalent')" >
      <template slot-scope="props">
        {{ 
          websocketDataps[props.row.crypto.replace("_V1","")+'USDT']?
          (websocketDataps[props.row.crypto.replace("_V1","")+'USDT']['a'] * (props.row.amount / 1).toFixed(8)).toFixed(2)
          : (props.row.amount / 1).toFixed(2)
          
           }}
      </template>
    </el-table-column>
	  
	  <el-table-column  :label="$t('field.upbalance')" > 
   			<template slot-scope="props">
          {{(props.row.amount - props.row.lockAmount).toFixed(8)}}
        </template>
	  </el-table-column>

	    <el-table-column prop="amount" :label="$t('field.dollarequivalent')">
      <template slot-scope="props">
        {{ 
          websocketDataps[props.row.crypto.replace("_V1","")+'USDT']?
          (websocketDataps[props.row.crypto.replace("_V1","")+'USDT']['a'] *  ((props.row.amount - props.row.lockAmount ) / 1).toFixed(8)).toFixed(2)
          :  ((props.row.amount - props.row.lockAmount ) / 1).toFixed(2)
          
           }}
      </template>
    </el-table-column>

      <el-table-column prop="lockAmount" :label="$t('field.lockAmount')" > </el-table-column>

      <el-table-column prop="depositAddress" :label="$t('field.updepositAddress')"> </el-table-column>
    
  		<el-table-column :label="$t('field.operation')" width="180" fixed="right" v-if="diction=='Dealing'?true:diction=='Compliance'?true:diction=='Admin'?true:false">
			<template slot-scope="props">
			<el-button size="mini" @click="updataUserMoney(props.row.uid,props.row.crypto,props.row.amount,props.row.type)">
				{{$t('field.updatebalance')}}
			</el-button>
			</template>
      	</el-table-column>

		  
    </el-table>
	<!-- 修改增加余额 -->
<div class="userUpdateMoney" v-if='upUserDataMoney'>
<div class="userUpdateForm">
 
 <h2>{{$t('field.updatebalance')}}</h2>
<el-form :model="upDateSurplus" ref="upDateSurplus" label-width="100px" class="demo-ruleForm">

  <el-form-item
    :label="$t('field.userid')">
	  <el-input  v-model="upDateSurplus.uid" autocomplete="off" readonly></el-input>
  </el-form-item>
  

  <el-form-item
    :label="$t('field.wallettype')">
	<el-select v-model="upDateSurplus.type" disabled>
		<el-option 
			v-for="item in optionsType"
			:key="item.value"
			:label="item.label"
			:value="item.value">
			</el-option>
		</el-select>
  </el-form-item>


    <el-form-item
    :label="$t('field.goodsname')">
    <el-input v-model="upDateSurplus.crypto" autocomplete="off" readonly></el-input>
  </el-form-item>
	
  <el-form-item
    :label="$t('userwallet.increasebalance')">
    <el-input v-model="upDateSurplus.amount" autocomplete="off"></el-input>
  </el-form-item>

    <el-form-item
    :label="$t('userwallet.lockedbalance')">
    <el-input v-model="upDateSurplus.lockAmount" autocomplete="off"></el-input>
  </el-form-item>

    <el-form-item
    :label="$t('field.remarks')">
    <el-input v-model="upDateSurplus.remark" autocomplete="off"></el-input>
  </el-form-item>
  

  <el-form-item>
    <el-button type="primary" @click="getUpdateSubmit()">{{$t('publicbtn.submitbtn')}}</el-button>
    <el-button @click="resetUpdateSubmit()">{{$t('publicbtn.cancel')}}</el-button>
  </el-form-item>
  
</el-form>
</div>

</div>
<!-- 更新交易钱包 -->
<div class="userUpdateMoney" v-show='reshUserTradeWallet'>
<div class="userUpdateForm">
 <h2>{{$t('field.updatebalance')}}</h2>
<el-form :model="reshUserTradeWalletMsg" ref="reshUserTradeWalletMsg" label-width="60px" class="demo-ruleForm">

  <el-form-item
    :label="$t('field.userid')">
	  <el-input  v-model="reshUserTradeWalletMsg.uid" autocomplete="off" oninput="value=value.replace(/[^\d]/g,'')"></el-input>
  </el-form-item>
  
  <el-form-item>
    <el-button type="primary" @click="getUserTradeWallet()">{{$t('publicbtn.submitbtn')}}</el-button>
    <el-button @click="resetUserTradeWallet()">{{$t('publicbtn.cancel')}}</el-button>
  </el-form-item>
  
</el-form>
</div>
</div>


  </div>
</template>
<script>
import excelexport from '@/components/export.vue'

import {getUserRequest,postUserRequest} from "@/api/api";
export default {
components: {
            excelexport,
        },
  data() {
    return {
	  reshUserTradeWalletMsg:{
		uid:null
	  },
	  reshUserTradeWallet:false,
	  diction:null,
	  type:1,
      uid:'',
	  remark:'',
      calculate:100000000,
      userDateList: [],
	  upUserDataMoney:false,
      loading: false,
	  upDateSurplus:{
		  lockAmount:'',
		  uid:'',
		  crypto:'',
		  amount:'',
		  type:'',
		  remark:''
	  },

    };
  },
  computed:{
	  websocketDataps(){
		  return this.$store.state.websocketDataps
	  },
optionsType:function(){
	return	[	 {
          value: 1,
          label:  this.$t('field.appWallet'),
        }, {
          value: 2,
          label: this.$t('field.otcWallet'),
        }]
}
  },
  methods: {
	//   查询
    getUserSubmit() {
      if (this.uid) {
			this.loading=true
			let params = {
			uid: this.uid,
			type:this.type,

        };
        getUserRequest(params, "/getUserTradeWallet").then((res) => {
			var data =res.data
				if (data.code == 200) {
					
			for(let i=0;i<data.data.length;i++){
				data.data[i].amount =( data.data[i].amount/this.calculate).toFixed(8)
				data.data[i].lockAmount =( data.data[i].lockAmount/this.calculate).toFixed(8)
			}
				this.userDateList = data.data;
				this.$message({
					message: data.message,
					 type: "success",
				}); 
				} else {
				this.$message({
				message: data.message,
				type: "error",
			});  
				}
				this.loading=false
        });
      } else {
        this.$message({
          message: this.$t('userwallet.userIDcannotbeempty'),
          type: "error",
        });
      }
    },
	//刷新 
	getUserRefresh(){
		
		this.getUserSubmit()
	},

	updataUserMoney(uid,crypto,amount,type){
		this.upDateSurplus.amount=''
		this.upDateSurplus.lockAmount = ''
		this.upDateSurplus.uid = uid 
		this.upDateSurplus.crypto = crypto 
		this.upDateSurplus.type = type
		this.upUserDataMoney = true
	},
	getUpdateSubmit(){
	var upDateSurplusSubmit = JSON.parse(JSON.stringify(this.upDateSurplus))

	if(upDateSurplusSubmit.amount!=''){
		if(upDateSurplusSubmit.amount>0){
			upDateSurplusSubmit['amount'] =parseInt((Number(upDateSurplusSubmit.amount)+0.0000000001)*this.calculate)
		}else{
			upDateSurplusSubmit['amount'] =parseInt((Number(upDateSurplusSubmit.amount)-0.0000000001)*this.calculate)
		}
	}
	if(upDateSurplusSubmit.lockAmount!=''){
		if(upDateSurplusSubmit.lockAmount>0){
upDateSurplusSubmit['lockAmount'] =parseInt((Number(upDateSurplusSubmit.lockAmount)+0.0000000001)*this.calculate)
		}else{
			upDateSurplusSubmit['lockAmount'] =parseInt((Number(upDateSurplusSubmit.lockAmount)-0.0000000001)*this.calculate)
	} 
	}

		postUserRequest(upDateSurplusSubmit,'/updateUserTradeWalletAmount').then((res)=>{
				let data = res.data
				if(data.code==200){
				this.getUserSubmit()
				}else{
				this.$message({
					message: data.message,
					type: "error",
					});
					}
				this.upUserDataMoney=false
			})
	},
	resetUpdateSubmit(){
		this.upUserDataMoney=false
	},
	// 更新用户交易钱包
	refreshUserTradeWallet(){
		this.reshUserTradeWallet=true
	},
	getUserTradeWallet(){
		if(this.reshUserTradeWalletMsg.uid){
		getUserRequest(this.reshUserTradeWalletMsg,'/refreshUserTradeWallet').then(res=>{
		let tradeWalletData = res.data
			if(tradeWalletData.code==200){
			this.$message({
				message: tradeWalletData.message,
				 type: "success",
			});
				
			}else{
			this.$message({
				message: tradeWalletData.message,
				type: "error",
			});
			}
		this.reshUserTradeWalletMsg.uid=null
		this.reshUserTradeWallet=false
		})
		}else{
			this.$message({
				message:this.$t('iptdefault.uid'),
				type: "error",
			});
		}

	},
	resetUserTradeWallet(){
		this.reshUserTradeWallet=false
		this.reshUserTradeWalletMsg.uid=null
	}

  },
  	created() {
    this.diction = sessionStorage.getItem("bospower");

  },
};
</script>

<style scoped>

.userUpdateMoney{
	position: fixed;
	top: 0;
	bottom: 0;
	right: 0;
	left: 0;
	background: rgba(0, 0, 0, 0.2);
	z-index: 9;
	}
.userUpdateForm{
	position: absolute;
	left: 50%;
	top: 50%;
	transform: translate(-50%, -50%);
	z-index: 99;
	padding: 20px;
	background: #fff;
	box-shadow: 0px 0px 3px #888;
	}

	.userUpdateMoney h2 {
  text-align: center;
  font-size: 18px;
}
</style>